#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

int myStrLen(char *s) {
	int n = 0;
	while (*++s != 0) {
		n++;
	}
	return n;
};

void myStrCpy(char *src, char *dst) {
	while (*src != 0) {
		*++dst = *++src;
	}
}
void myStrConcat(char *string1, char *string2) {
	int l1 = myStrLen(string1);
	int l2 = myStrLen(string2);

	for(int i=0;i< l2;i++) {
		(i + l1)[string1] = i[string2];
	}
	(l2 + l1)[string1] = 0;
};


int main() {
	char* strArr[1024];

	int order[1024] = { 0 };

	int n, a, b;
	scanf("%d %d %d", &n, &a, &b);

	for (int i = 0; i < n; i++) {
		scanf("%d", &order[i]);
		strArr[i] = (char*)malloc(1024);
	}

	for (int i = 0; i < n; i++) {
		scanf("%s", strArr[i]);
	}

	myStrConcat(strArr[a], strArr[b]);

	for (int i = 0; i < n && putchar(' '); i++) {
		printf("%d", myStrLen(strArr[i]));
	}

	putchar('\n');

	for (int i = 0; i < n; i++) {
		puts(strArr[order[i]]);
	}
}
